//
//  EditeViewController.swift
//  SwiftDemo
//
//  Created by 李文强 on 2017/1/11.
//  Copyright © 2017年 李文强. All rights reserved.
//

import UIKit

class EditeViewController: UIViewController {

    //删除的view的懒加载
    lazy var deleteView:UIView = {
       let delView = UIView()
        delView.backgroundColor = UIColor.white
        return delView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.modalPresentationStyle = .custom
        
//        self.view.alpha = 0.8
        self.myDeleteView()
        // Do any additional setup after loading the view.
    }
//MARK:下方的删除视图按钮
    func myDeleteView() -> Void {
        self.view.addSubview(deleteView)
        self.deleteView.mas_makeConstraints { (make:MASConstraintMaker?) in
            make!.left.equalTo()(0)
            make!.right.equalTo()(0)
            make!.bottom.equalTo()(0)
            make!.height.equalTo()(45)
        }
        //添加删除按钮
        let deleBtn = UIButton()
        deleBtn.setTitle("取消", for: UIControlState.normal)
        deleBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        deleBtn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        deleBtn.layer.masksToBounds = true
        deleBtn.layer.cornerRadius = 15
        deleBtn.addTarget(self, action: #selector(deletClick(but:)), for: UIControlEvents.touchUpInside)
        self.deleteView.addSubview(deleBtn)
        deleBtn.mas_makeConstraints { (make:MASConstraintMaker?) in
            make!.centerX.equalTo()(self.deleteView.mas_centerX)
            make!.top.equalTo()(5)
            make!.bottom.equalTo()(5)
            make!.width.equalTo()(30)
            make!.height.equalTo()(30)
        }
        self.createButton()
        self.animation()
        
    }
    //MARK:function of delete Button
    func deletClick(but:UIButton) -> Void {
        self.dismiss(animated: true, completion: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //MARK:文字，头条
    func createButton() -> Void {
        //MARK:TextButton
        for i in 0..<6 {
            let w:CGFloat = Screen.width*(3/16)
            let j:CGFloat = Screen.width*(35/320)
            let y:Int = Int(CGFloat(i) / 3.0)
            let x:Int = i % 3
            let button = UIButton.init(frame: CGRect(x:j+CGFloat(x)*(w+j),y:CGFloat(y)*(w+20)+Screen.height/2+200,width:w,height:w));
            button.backgroundColor = UIColor.red
            button.layer.cornerRadius = w/2
            button.layer.masksToBounds = true
            button.setTitle(String.init(i), for: UIControlState.normal)
            button.tag = i+100
            self.view.addSubview(button)
        }
     }

//MARK:annimation
    func animation() -> Void{
            for i in 0..<6 {
                let w:CGFloat = Screen.width*(3/16)
                let j:CGFloat = Screen.width*(35/320)
                let y:Int = Int(CGFloat(i) / 3.0)
                let x:Int = i % 3
                UIView.animate(withDuration: 2, animations: ({
                let button:UIButton = self.view.viewWithTag(100+i) as! UIButton
                button.frame = CGRect(x:j+CGFloat(x)*(w+j),y:CGFloat(y)*(w+20)+Screen.height/2,width:w,height:w)
                    
                }))
            }
        
      
    }
    //MARK:-weatherView
    func weathgerFun() -> Void{
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
